{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 随机漫步"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7fc8b66c47d0>]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAYAAAAAczaOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAf40lEQVR4nO3deXxV5b3v8c9v750BCFMgTCHMoKIoaASsE9VqFbXUntZKB6m10kHbnr6893a6t9r29Nb29rTWa+upIoLa4mxBpVWktGgpylBmEMIkCSEJIGOSPT7nj72wQYiQZGevnb2/79crr732s1ayf+u1wjeLZz3rWeacQ0REckPA7wJERCR9FPoiIjlEoS8ikkMU+iIiOUShLyKSQ0J+F/BBevfu7YYMGeJ3GSIiHcqKFSv2OudKTrYuo0N/yJAhLF++3O8yREQ6FDPb2dw6de+IiOQQhb6ISA5R6IuI5BCFvohIDlHoi4jkEIW+iEgOUeiLiOSQjB6nLyKSzV7bUMP63YcoyAtQGApQkBekIBSgIBSkd1E+E4b1SvlnKvRFRHzQEInz9Tn/pCEaP+n6cYN68MLXLk755yr0RUR8sOjtWhqicZ64bQLnD+5BYzRBJJYgHIsTjiUIBaxdPlehLyLig5fXVNO7KJ+LhvciGDA656fnc095IdfMysxskZltMLP1ZvZNr73YzBaY2RbvtafXbmZ2v5lVmNkaMzu/yc+a5m2/xcymtd9uiYhkroZInL9squWac/oRbKcz+uaczuidGHCX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cQukJyQymObjaGfUw9fN7M8koH/e+fc815zzbH/7nmvtX7V1w4uBj5mZjtIdt1dQbKvu4fXBQDZecwrgUrn3Jve+2dJ/hHI5mP9EWC7c67OORcFnid5/LP9WB/T3LFtU8ZlY+jnzMPXvb7sR4CNzrlfNlk1D5jmLU8D5qa7tvbinPuuc26gc24IyWP7F+fcZ4FFwCe9zbJqnwGcc3uAXWZ2htd0JbCBLD7WJLt1JppZZ+93/dg+Z/WxbqK5YzsPuMUbxTMRONikG+jUnHNZ9wVMBjYDW4Hv+11PO+7nJST/y7cGWOV9TSbZx70Q2AK8BhT7XWs77f8k4CVveRjwFlABPAMU+F1fO+zvWGC5d7z/CPTM9mMN/BDYBKwDHgcKsvFYA3NIXreIkvxf3W3NHVvASI5Q3AqsJTm66bQ/S9MwiIjkkGzs3hERkWYo9EVEcohCX0Qkhyj0RURyiEJfRCSHKPRFRHKIQl9EJIf8N+0VSj8gnHZTAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "position = 0\n",
    "walk = [position]\n",
    "steps = 1000\n",
    "for i in range(steps):\n",
    "    step = i if random.randint(0, 1) else -1\n",
    "    position += step\n",
    "    walk.append(position)\n",
    "\n",
    "plt.plot(walk[:100])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "nsteps = 1000\n",
    "draws = np.random.randint(0, 2, size=nsteps)\n",
    "steps = np.where(draws>0, 1, -1)\n",
    "walk = steps.cumsum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  1,   0,  -1,  -2,  -3,  -4,  -3,  -4,  -3,  -2,  -1,  -2,  -3,\n",
       "        -2,  -3,  -2,  -1,  -2,  -1,   0,   1,   2,   1,   2,   1,   0,\n",
       "         1,   0,  -1,  -2,  -1,  -2,  -1,  -2,  -1,   0,  -1,   0,   1,\n",
       "         0,  -1,   0,  -1,   0,  -1,   0,   1,   0,  -1,   0,  -1,   0,\n",
       "         1,   2,   1,   0,  -1,  -2,  -3,  -2,  -1,  -2,  -1,   0,  -1,\n",
       "        -2,  -3,  -2,  -3,  -4,  -5,  -6,  -7,  -8,  -9, -10, -11, -12,\n",
       "       -13, -14, -13, -14, -15, -14, -13, -12, -13, -12, -13, -14, -13,\n",
       "       -12, -13, -14, -15, -16, -17, -18, -17, -18, -17, -16, -15, -14,\n",
       "       -13, -12, -11, -12, -11, -12, -11, -12, -13, -14, -13, -14, -13,\n",
       "       -14, -13, -14, -15, -16, -17, -18, -19, -18, -19, -20, -19, -18,\n",
       "       -17, -18, -19, -18, -19, -18, -17, -16, -17, -18, -17, -18, -17,\n",
       "       -18, -19, -18, -17, -16, -17, -16, -17, -18, -19, -20, -21, -22,\n",
       "       -23, -24, -23, -22, -23, -22, -23, -24, -25, -26, -25, -26, -27,\n",
       "       -26, -27, -26, -27, -28, -29, -28, -29, -30, -29, -28, -29, -30,\n",
       "       -29, -28, -29, -30, -31, -30, -31, -32, -33, -34, -33, -32, -31,\n",
       "       -32, -31, -32, -33, -32, -31, -30, -31, -30, -31, -32, -31, -32,\n",
       "       -33, -32, -31, -32, -31, -32, -31, -30, -31, -32, -33, -34, -35,\n",
       "       -34, -35, -36, -35, -34, -33, -32, -31, -32, -31, -32, -33, -32,\n",
       "       -33, -34, -33, -34, -35, -36, -35, -34, -35, -34, -33, -34, -33,\n",
       "       -32, -31, -32, -31, -32, -31, -32, -31, -32, -33, -34, -33, -34,\n",
       "       -35, -34, -35, -34, -33, -34, -35, -34, -33, -34, -35, -36, -35,\n",
       "       -34, -35, -36, -35, -34, -35, -34, -33, -34, -35, -36, -35, -34,\n",
       "       -35, -36, -37, -36, -37, -36, -35, -36, -37, -38, -39, -38, -39,\n",
       "       -40, -41, -42, -43, -44, -43, -44, -43, -42, -43, -42, -41, -42,\n",
       "       -43, -44, -45, -46, -47, -46, -47, -48, -49, -50, -49, -50, -51,\n",
       "       -50, -51, -52, -53, -52, -53, -52, -51, -52, -53, -52, -51, -50,\n",
       "       -51, -50, -49, -50, -49, -50, -49, -48, -49, -50, -49, -48, -47,\n",
       "       -46, -45, -46, -47, -46, -45, -46, -45, -44, -45, -44, -43, -44,\n",
       "       -43, -42, -41, -40, -39, -38, -37, -38, -37, -36, -37, -36, -37,\n",
       "       -38, -39, -38, -39, -40, -39, -40, -41, -40, -39, -38, -37, -36,\n",
       "       -35, -34, -35, -34, -35, -36, -37, -36, -35, -34, -35, -36, -37,\n",
       "       -38, -37, -36, -37, -38, -37, -36, -35, -36, -37, -38, -39, -38,\n",
       "       -39, -40, -39, -40, -39, -40, -41, -40, -41, -40, -39, -38, -39,\n",
       "       -38, -37, -38, -37, -36, -37, -36, -35, -34, -35, -36, -35, -36,\n",
       "       -37, -36, -37, -38, -39, -38, -39, -40, -41, -42, -41, -40, -41,\n",
       "       -42, -43, -42, -43, -44, -45, -44, -43, -44, -43, -42, -43, -42,\n",
       "       -41, -42, -41, -40, -41, -42, -41, -40, -41, -40, -41, -42, -43,\n",
       "       -42, -41, -42, -41, -42, -43, -44, -45, -46, -45, -44, -45, -46,\n",
       "       -45, -44, -45, -44, -45, -44, -43, -44, -45, -44, -45, -46, -45,\n",
       "       -46, -45, -44, -43, -42, -43, -44, -45, -46, -45, -46, -47, -46,\n",
       "       -45, -46, -47, -48, -49, -50, -51, -50, -49, -50, -51, -52, -51,\n",
       "       -52, -51, -52, -51, -50, -49, -48, -49, -48, -49, -48, -47, -46,\n",
       "       -47, -48, -47, -46, -47, -48, -47, -48, -49, -50, -51, -50, -51,\n",
       "       -52, -51, -52, -51, -52, -51, -50, -51, -50, -49, -50, -51, -52,\n",
       "       -53, -52, -51, -50, -51, -50, -51, -50, -51, -50, -51, -50, -49,\n",
       "       -48, -47, -46, -47, -46, -45, -46, -47, -48, -47, -46, -45, -44,\n",
       "       -45, -44, -43, -44, -43, -42, -41, -40, -41, -42, -43, -44, -43,\n",
       "       -44, -45, -46, -47, -46, -47, -46, -45, -44, -45, -46, -45, -46,\n",
       "       -47, -46, -47, -48, -47, -46, -47, -46, -45, -46, -45, -44, -45,\n",
       "       -46, -47, -48, -49, -50, -49, -50, -49, -48, -49, -48, -49, -48,\n",
       "       -49, -48, -47, -46, -45, -44, -45, -46, -45, -46, -45, -44, -43,\n",
       "       -42, -41, -42, -41, -40, -39, -40, -39, -40, -39, -40, -41, -40,\n",
       "       -39, -40, -41, -42, -43, -42, -43, -42, -43, -42, -41, -42, -41,\n",
       "       -42, -43, -42, -41, -40, -39, -40, -39, -40, -41, -42, -41, -42,\n",
       "       -41, -42, -41, -42, -41, -40, -41, -42, -41, -42, -43, -44, -45,\n",
       "       -46, -47, -46, -47, -46, -47, -46, -47, -46, -47, -46, -45, -46,\n",
       "       -47, -48, -49, -48, -47, -48, -49, -48, -49, -50, -51, -50, -51,\n",
       "       -50, -51, -50, -51, -50, -49, -50, -51, -50, -51, -50, -51, -50,\n",
       "       -49, -50, -49, -48, -49, -50, -51, -52, -53, -52, -51, -50, -49,\n",
       "       -48, -49, -48, -47, -46, -47, -46, -47, -46, -47, -46, -47, -46,\n",
       "       -45, -44, -45, -44, -45, -46, -45, -46, -45, -44, -45, -46, -47,\n",
       "       -48, -47, -48, -49, -48, -47, -46, -47, -46, -47, -48, -49, -50,\n",
       "       -49, -50, -51, -50, -49, -50, -51, -52, -51, -50, -49, -48, -49,\n",
       "       -48, -49, -48, -47, -46, -45, -46, -45, -46, -47, -46, -45, -46,\n",
       "       -47, -48, -47, -46, -45, -44, -43, -44, -45, -46, -47, -48, -47,\n",
       "       -46, -45, -44, -45, -46, -47, -46, -47, -46, -45, -46, -47, -46,\n",
       "       -45, -46, -45, -44, -43, -44, -43, -42, -43, -42, -43, -44, -45,\n",
       "       -46, -47, -46, -47, -46, -47, -48, -47, -48, -49, -48, -49, -48,\n",
       "       -47, -48, -47, -46, -47, -48, -47, -48, -47, -48, -49, -50, -49,\n",
       "       -48, -47, -46, -45, -46, -47, -46, -45, -44, -43, -44, -45, -46,\n",
       "       -47, -46, -45, -46, -47, -46, -45, -46, -47, -46, -45, -44, -43,\n",
       "       -44, -43, -44, -45, -44, -43, -42, -43, -42, -41, -40, -39, -38,\n",
       "       -37, -38, -37, -36, -37, -36, -37, -38, -39, -40, -41, -42, -41,\n",
       "       -40, -41, -42, -41, -42, -43, -44, -45, -44, -45, -44, -45, -44,\n",
       "       -43, -42, -43, -42, -41, -42, -41, -40, -41, -40, -39, -38, -39,\n",
       "       -40, -39, -38, -37, -36, -35, -34, -35, -34, -35, -34, -33, -34,\n",
       "       -35, -34, -33, -32, -33, -34, -35, -36, -35, -34, -33, -32])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "walk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-53"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "walk.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "walk.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "75"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(np.abs(walk) >= 10).argmax()"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3207008acf26a07c58f9163727980777c0d92fa298586eda8a314250b7931cb4"
  },
  "kernelspec": {
   "display_name": "Python 3.7.10 ('pybd')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
